import java.util.Arrays;
import java.util.Scanner;

public class Main4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long M = sc.nextLong();
        long []player = new long[N];
        for(int i = 0;i < N;i++){
            long num = sc.nextLong();
            player[i] = num;
        }
        long res = least(player,N,M);
        System.out.println(res);
        sc.close();

    }

    private static long least(long[] player,int N,long M){
        long res = 0;
        for(int i = 0;i <  M;i++){
            Arrays.sort(player);
            long min = player[0];
            long max = player[N-1];
            if(max - min > 1){
                player[0] ++;
                player[N-1]--;
            }else{
                break;
            }
        }
        Arrays.sort(player);
        res = player[N- 1] - player[0];
        return res;

    }
}
